home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_08
/
9n08068a
< prev
next >
Wrap
Text File
|
1991-06-19
|
4KB
|
174 lines
Listing 2 - The Function print_hist_image (file djet.c)
/***********************************
*
* print_hist_image(...
*
************************************/
print_hist_image(printer, hist)
FILE *printer;
unsigned long hist[];
{
char c, d;
int i, j, k;
unsigned long limit, max;
d = 0;
c = 255;
/********************************
*
* First scale the histogram
*
*********************************/
max = 0;
for(i=0; i<256; i++)
if(hist[i] > max) max = hist[i];
if(max > 200){
for(i=0; i<256; i++){
hist[i] = (hist[i]*200)/max;
}
}
/********************************
*
* Second print it
*
* Print a space between the image
* and the histogram.
*
*********************************/
for(i=0; i<20; i++){
end_graphics_mode(printer);
select_300_dpi_resolution(printer);
set_raster_width(printer);
start_raster_graphics(printer);
select_full_graphics_mode(printer);
set_horizontal_offset(printer);
putc(ESCAPE, printer);
putc('*', printer);
putc('b', printer);
putc('2', printer);
putc('0', printer);
putc('0', printer);
putc('W', printer);
for(j=0; j<200; j++)
putc(d, printer);
}
printf("\n\nHIST> Now printing the histogram");
for(i=0; i<256; i++){
printf("\n\tHIST> Histogram[%d]=%ld", i, hist[i]);
/* print the line 2 times */
for(k=0; k<2; k++){
end_graphics_mode(printer);
select_300_dpi_resolution(printer);
set_raster_width(printer);
start_raster_graphics(printer);
select_full_graphics_mode(printer);
/***************************
*
* Print grid marks every
* 50 pixels. Do this by
* setting a shorter margin
* then printing 2 marks then
* the data.
*
****************************/
if( (i == 0) ||
(i == 50) ||
(i == 100) ||
(i == 150) ||
(i == 200) ||
(i == 255)){
set_shorter_horizontal_offset(printer);
putc(ESCAPE, printer);
putc('*', printer);
putc('b', printer);
putc('2', printer);
putc('0', printer);
putc('2', printer);
putc('W', printer);
putc(c, printer);
putc(c, printer);
if(hist[i] >= 200)
hist[i] = 200;
limit = 200 - hist[i];
if(hist[i] == 0)
putc(c, printer);
for(j=0; j<hist[i]; j++)
putc(c, printer);
for(j=0; j<limit; j++)
putc(d, printer);
} /* ends print grid marks */
/***************************
*
* If you do not print
* grid marks, set the normal
* margin and then print the
* data.
*
****************************/
else{
set_horizontal_offset(printer);
/* this prints 200 bytes so print 200 */
putc(ESCAPE, printer);
putc('*', printer);
putc('b', printer);
putc('2', printer);
putc('0', printer);
putc('0', printer);
putc('W', printer);
if(hist[i] >= 200)
hist[i] = 200;
limit = 200 - hist[i];
if(hist[i] == 0)
putc(c, printer);
for(j=0; j<hist[i]; j++)
putc(c, printer);
for(j=0; j<limit; j++)
putc(d, printer);
} /* ends else no grid marks */
} /* ends loop over k */
} /* ends loop over i */
} /* ends print_hist_image */